// Copyright 2007 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package lichen.internal.utils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * 对注释进行常规操作的类.
 * @author jcai
 * @version $Revision: 191 $
 * @since 0.0.3
 */
public final class AnnotationUtil {
	/**
	 * 判断一个类中是否出现了Annotation.包含了检查类本身以及类的方法.
	 * @param clazz 待检查的类.
	 * @param annotationClass 注释类.
	 * @return 是否出现.
	 * @since 0.0.3
	 */
	public static boolean isAnnotationPresent(Class<?> clazz,Class<? extends Annotation> annotationClass){
		//先判断类本身.
		if(clazz.isAnnotationPresent(annotationClass)){
			return true;
		}
		//方法进行遍历.
		for(Method method:clazz.getMethods()){
			if(method.isAnnotationPresent(annotationClass)){
				return true;
			}
		}
		return false;
	}
}
